package com.manaka.service;

import com.manaka.bean.Message;
import com.manaka.dao.MessageDao;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Manaka
 * @date 2018-09-06 12:27
 * 维护相关业务功能
 */
public class MaintainService {
    /**
     * 单条删除
     * @param id
     */
    public void deleteOne(String id){
        if(id != null && !"".equals(id)){
            MessageDao dao = new MessageDao();
            dao.deleteOne(Integer.valueOf(id));
        }
    }

    /**
     * 批量删除
     * @param list
     */
        public void deleteBatch(String[] list){
        if(list.length != 0){
            List<Integer> idList = new ArrayList<Integer>();
            for (String id:list){
                idList.add(Integer.valueOf(id));
            }
            MessageDao dao = new MessageDao();
            dao.deleteBatch(idList);
        }
    }

    /**
     * 添加指令
     * @param command
     * @param description
     * @param content
     */
    public void addCommand(String command,String description,String content){
            if (command != null && !"".equals(command)){
                MessageDao dao = new MessageDao();
                dao.addCommand(command,description,content);
            }
    }

    /**
     * 前台机器人自动回复功能
     * @param command
     * @return
     */
    public String autoReply(String command){
        MessageDao dao = new MessageDao();
        Message message = dao.autoReply(command);
        if (message == null){
            return "哎呀，你所查询的内容不存在哦";
        }else {
            return message.getContent();
        }
    }

}
